<?php

/*
 * File  : Transaksi.php
 * Table : transaksi, kategoris
 */
//session_start();
//cek session

if ((!$_SESSION["USRID"] AND !$_SESSION["USRPASS"])) {
    header("location: ../index.php");
    exit();
}
//end
?>

<?php

$aksi = "cms/bab/m_transaksi/aksi_transaksi.php";
echo "<form method='POST' action ='?module=trans&opr=search&net=" . $_POST[ct] . "'>";
echo " Masukkan Total Harga <input name='ct' type='text' size='200' placeholder='Total Harga' />";
echo "</form>";

switch ($_GET["opr"]) {

    // tampil transaksi
    default:
        echo " <table>";
        echo "  <tr><th>No</th><th>Kode</th><th>No Unik</th><th>Tanggal Order</th><th>Total</th><th>No. Resi</th><th>Pembeli</th><th>No Telepon</th><th>Email</th><th>Status</th><th>Aksi</th></tr>";

        $p = new Paging;
        $batas = 10;
        $posisi = $p->cariPosisi($batas);

        $tampil = mysql_query("SELECT * FROM tr_x ORDER BY trx_waktu DESC, trx_status ASC LIMIT $posisi, $batas");

        $no = $posisi + 1;
        while ($row = mysql_fetch_array($tampil)) {
            $tanggal = tgl_indo($row["trx_waktu"]);
            $harga = format_rupiah($row["trx_total"]);
            echo "<tr><td>$no</td>";
            echo " <td>" . $row["trx_kodeunik"] . "</td>";
            echo " <td>" . $row["trx_angkaunik"] . "</td>";
            echo " <td>" . $tanggal . "</td>";
            echo " <td align=right>Rp " . $harga . "</td>";
            echo " <td align=center>" . $row["trx_noresi"] . "</td>";
            echo " <td>" . $row["trx_nama"] . "</td>";
            echo " <td>" . $row["trx_notelp"] . "</td>";
            echo " <td>" . $row["trx_email"] . "</td>";
            echo " <td>" . get_status_transaksi($row["trx_status"]) . "</td>";
            echo " <td><a href='?module=trans&opr=view&id=" . $row["trx_id"] . "'>Details</a> | 
						<a href='?module=trans&opr=edit&id=" . $row["trx_id"] . "'>Edit</a> | 
		                <a href='" . URLHOST . "$aksi?module=trans&opr=hapus&id=" . $row["trx_id"] . "'  onClick=\"return confirm('Hapus Transaksi Dengan No. Nota " . $row["trx_kodeunik"] . "?')\" >Hapus</a>";
            echo " </td></tr>";
            $no++;
        }
        echo "</table>";

        $jmldata = mysql_num_rows(mysql_query("SELECT * FROM tr_x"));
        $jmlhalaman = $p->jumlahHalaman($jmldata, $batas);
        $linkHalaman = $p->navHalaman($_GET["halaman"], $jmlhalaman);

        echo "<div id=paging>Hal: $linkHalaman</div><br>";
        break;

    // cek transaksi
    case "search":
        echo " <table>";
        echo "  <tr><th>No</th><th>Kode</th><th>No Unik</th><th>Tanggal Order</th><th>Total</th><th>No. Resi</th><th>Pembeli</th><th>No Telepon</th><th>Email</th><th>Status</th><th>Aksi</th></tr>";

        $p = new Paging;
        $batas = 10;
        $posisi = $p->cariPosisi($batas);

        $tampil = mysql_query("SELECT * FROM tr_x where trx_total like '%" . $_POST['ct'] . "%' or trx_id like '%" . $_POST['ct'] . "%'  ORDER BY trx_waktu DESC, trx_status ASC LIMIT $posisi, $batas");

        $no = $posisi + 1;
        while ($row = mysql_fetch_array($tampil)) {
            $tanggal = tgl_indo($row["trx_waktu"]);
            $harga = format_rupiah($row["trx_total"]);
            echo "<tr><td>$no</td>";
            echo " <td>" . $row["trx_kodeunik"] . "</td>";
            echo " <td>" . $row["trx_angkaunik"] . "</td>";
            echo " <td>" . $tanggal . "</td>";
            echo " <td align=right>" . $harga . "</td>";
            echo " <td align=center>" . $row["trx_noresi"] . "</td>";
            echo " <td>" . $row["trx_nama"] . "</td>";
            echo " <td>" . $row["trx_notelp"] . "</td>";
            echo " <td>" . $row["trx_email"] . "</td>";
            echo " <td>" . get_status_transaksi($row["trx_status"]) . "</td>";
            echo " <td><a href='?module=trans&opr=view&id=" . $row["trx_id"] . "'>Details</a> | 
						<a href='?module=trans&opr=edit&id=" . $row["trx_id"] . "'>Edit</a> | 
		                <a href='" . URLHOST . "$aksi?module=trans&opr=hapus&id=" . $row["trx_id"] . "'  onClick=\"return confirm('Hapus Transaksi Dengan No. Nota " . $row["trx_kodeunik"] . "?')\" >Hapus</a>";
            echo " </td></tr>";
            $no++;
        }
        echo "</table>";

        $jmldata = mysql_num_rows(mysql_query("SELECT * FROM tr_x"));
        $jmlhalaman = $p->jumlahHalaman($jmldata, $batas);
        $linkHalaman = $p->navHalaman($_GET["halaman"], $jmlhalaman);

        echo "<div id=paging>Hal: $linkHalaman</div><br>";
        break;

    case "view":
        echo " <table>";
        echo "  <tr><th>No</th><th>Nama Produk</th><th>Jumlah</th><th>Subtotal</th><th>Ukuran</th><th>Berat</th>";
        $p = new Paging;
        $batas = 10;
        $posisi = $p->cariPosisi($batas);

        $tampil = mysql_query("SELECT produks.produk_nama, tr_d.trd_jumlah, tr_d.trd_harga, tr_d.trd_ukuran, tr_d.trd_berat
                                FROM tr_d
                                INNER JOIN produks ON produk_id = tr_d.trd_produk_id
                                INNER JOIN tr_x ON tr_x.trx_id = tr_d.trd_trx_id
                                WHERE tr_x.trx_id = '" . $_GET["id"] . "'");

        $no = $posisi + 1;
        while ($row = mysql_fetch_array($tampil)) {

            $harga = format_rupiah($row["trd_harga"]);
            echo "<tr><td>$no</td>";
            echo " <td>" . strtoupper($row["produk_nama"]) . "</td>";
            echo " <td align=center>" . $row["trd_jumlah"] . "</td>";
            echo " <td align=right>" . $harga . "</td>";
            echo " <td align=center>" . strtoupper($row["trd_ukuran"]) . "</td>";
            echo " <td align=center>" . $row["trd_berat"] . "</td>";
            echo " </tr>";
            $no++;
        }
        echo " </table>";
        //echo "  <input type ='button' value ='Batal' onclick ='self.history.back()'></td></tr>";
        echo " <a href='?module=trans'>Back</a></td></tr>";
        break;

    case "edit":
        $edit = mysql_query("SELECT * FROM tr_x WHERE trx_id= '" . $_GET["id"] . "'");
        $row = mysql_fetch_array($edit);

        echo "<h2>Edit Transaksi</h2>";
        echo " <form method='POST' action ='" . URLHOST . "$aksi?module=trans&opr=update' enctype='multipart/form-data'>";
        echo " <input type ='hidden' name ='id' value ='" . $row["trx_id"] . "'>";
        echo " <table>";
        echo "  <tr><td width = 100>Kode Transaksi</td> <td> : " . $row["trx_kodeunik"] . "</td></tr>";
        echo "  <tr><td>Tanggal Beli</td> <td> : " . $row["trx_waktu"] . "</td></tr>";
        echo "  <tr><td>Pembeli</td> <td> : " . strtoupper($row["trx_nama"]) . "</td></tr>";
        echo "  <tr><td>No. Resi</td> <td> : <input name='in_no_resi' type='text' value='" . $row["trx_noresi"] . "'></td></tr>";
        echo "  <tr><td>Status Transaksi</td>  <td> :";
        echo "   <select name='in_transaksi_status_id'>";
        $tampil = mysql_query("SELECT * FROM status ORDER BY status_id");
        if ($row["trx_status"] == 0) {
            echo "<option value = 0 selected>- Pilih Status -</option>";
        }

        while ($w = mysql_fetch_array($tampil)) {
            if ($row["trx_status"] == $w["status_id"]) {
                echo "<option value ='" . $w["status_id"] . "' selected>" . $w["status_nama"] . "</option>";
            } else {
                echo "<option value ='" . $w["status_id"] . "'>" . $w["status_nama"] . "</option>";
            }
        }
        echo "   </select></td></tr>";
        echo "  <tr><td colspan='2'><input type ='submit' value ='Simpan'>";
        echo "  <input type ='button' value ='Batal' onclick ='self.history.back()'></td></tr>";
        echo "</table></form>";
        break;
}
?>
